# 英雄相册
from tkinter import *
from PIL import Image
from PIL import ImageTk
import os

root = Tk()
root.title('英雄相册')

current_img_name = 1
# 本地图片的路径
img_path = "./素材包/LOL/"
# 打开图片
img_list = os.listdir(img_path)
img = Image.open(img_path + "图片.jpg")
img = ImageTk.PhotoImage(img)


# 定义标签
label = Label(root, width=980, height=500, image = img)
label.grid(row=0, column=0, columnspan=2)

# 上一张按钮事件函数
def callback_pre():
    global current_img_name
    current_img_name -= 1
    if current_img_name == 0:
        current_img_name = 6
    img_new = Image.open(img_path + str(current_img_name) + ".jpg")
    img_new = ImageTk.PhotoImage(img_new)
    # 更改指向
    label.configure(image = img_new)
    label.image = img_new

# 下一张按钮事件函数
def callback_next():
    # print("打开下一张图片")
    global current_img_name
    current_img_name += 1
    if current_img_name == 7:
        current_img_name = 1
    img_new = Image.open(img_path + str(current_img_name) + ".jpg")
    img_new = ImageTk.PhotoImage(img_new)
    # 更改指向
    label.configure(image = img_new)
    label.image = img_new

# 上一张按钮
btn_pre = Button(root, text="上一张", font=("黑体",20), command=callback_pre)
btn_pre.grid(row=1, column=0)
# 下一张按钮
btn_next = Button(root, text="下一张", font=("黑体",20), command=callback_next)
btn_next.grid(row=1, column=1)

root.mainloop()